const formatTime = date => {
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()

  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}

// 匹配错误码信息
const errorCodeToast = data => {
  var modalContent = '数据请求错误！';
  var errorCode = data.errno;
  switch (errorCode) {
    case 10004:
      {
        modalContent = '查询不到数据！';
        break;
      };
    case 40000:
      {
        modalContent = '参数错误';
        break;
      };
    case 40001:
      {
        modalContent = '请您重新登录！';
        break;
      };
    default:
      break;
  }
  wx.showModal({
    title: '提示',
    showCancel: false,
    confirmText: '知道了',
    content: modalContent
  });
}




module.exports = {
errorCodeToast: errorCodeToast,
formatTime: formatTime
}

